package com.analysis.listener;

import java.util.List;
import java.util.Map;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.analysis.common.ConfigUtil;
import com.analysis.service.impl.DataSetServiceImpl;
import com.analysis.service.impl.KLineServiceImpl;
import com.analysis.service.impl.StoreService;

@Component
public class StartUpListener implements CommandLineRunner{

    @Override
    public void run(String... args) throws Exception {
    	if("true".equalsIgnoreCase(ConfigUtil.getString("loadData"))){
    		System.out.println("Load stock data...");
        	StoreService store = StoreService.getInstance();
        	KLineServiceImpl klineService = new KLineServiceImpl();
        	Map<String, List<String>> set = DataSetServiceImpl.getDataSet();
        	
        	for(List<String> symbolList:set.values()){
        		symbolList.parallelStream().forEach(each->{
        			store.saveKline(each, klineService.getKline(each));
        			System.out.println("Loaded "+each);
        		});
        	}
         
    	}
    	   System.out.println("System started up ...");
    }
}
